package com.mezz.bones.im.logic.controller;

import com.mezz.bones.framework.base.domain.response.Result;
import com.mezz.bones.im.common.message.body.in.ConversationRecordReq;
import com.mezz.bones.im.common.message.body.out.ConversationRecordRes;
import com.mezz.bones.im.logic.domain.request.ApiMessageUnReadCountRequest;
import com.mezz.bones.im.logic.domain.response.ApiMessageUnReadCountResponse;
import com.mezz.bones.im.logic.repository.IChatConversationRepository;
import com.mezz.bones.im.logic.service.IChatConversationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api("IM会话管理")
@RequestMapping("/im/conversation")
@RestController
@AllArgsConstructor
public class ChatConversationController {

    private final IChatConversationRepository conversationRepository;
    private final IChatConversationService conversationService;

    @PostMapping("/unread/count")
    @ApiOperation("用户消息未读数(包含单聊/群聊)")
    public Result<ApiMessageUnReadCountResponse> apiCountUnreadMessage(@Valid @RequestBody ApiMessageUnReadCountRequest request) {

        return Result.OK(conversationRepository.countUnreadMessage(request.getUserId()));
    }

    @PostMapping("/record")
    @ApiModelProperty("IM用户会话列表数据")
    public Result<?> apiConversationRecord(@RequestBody @Valid ConversationRecordReq request) {

        Map<String,Object> res = new HashMap<>();
        res.put("list",conversationService.getUserConversationRecord(request));
        return Result.OK(res);
    }
}
